package com.yyb.utils.core;

import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * File操作工具类
 *
 * @Author : Marshal
 * @Create : 2018/2/10 13:18
 */
public class FileUtil {

    /**
     * File转换成MutipartFile
     *
     * @param file
     * @return
     */
    public static MultipartFile fileToMultipartFile(File file){
        try {
            FileInputStream inputStream = new FileInputStream(file);
            MultipartFile multipartFile = new MockMultipartFile(file.getName(), inputStream);
            return multipartFile;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

}
